package cn.edu.buaa.cnsatm.traffic_big_data_server.integrated.controller;

import cn.edu.buaa.cnsatm.traffic_big_data_server.highway.service.HighwayTSService;
import cn.edu.buaa.cnsatm.traffic_big_data_server.integrated.service.RoadStatusService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;

@RestController
public class RoadStatusController {
    @RequestMapping("/trafficEvent")
    @ResponseBody
    public String webGetRoadStatus(
            @RequestParam(value = "top_num", name = "top_num", required = true, defaultValue = "5") int top_num
    ) throws SQLException {
        /**
         * @author LX
         * @description 综合交通事件
         * @date 2019-11-05
         */
        return RoadStatusService.getTopKRoadEvent(top_num);
    }

    @RequestMapping("/getRoadStatusSQLString")
    @ResponseBody
    public String webGetRoadStatusSQLString(
            @RequestParam(value = "cookie", name = "cookie", required = false) String cookie
    ) throws SQLException, ParseException, InterruptedException, IOException {
        /**
         * @author LX
         * @description 综合交通事件
         * @date 2019-11-05
         */
        if(cookie == null || cookie.equals("")) return "开爬之前管LX要cookie";
        return RoadStatusService.getRoadStatusSQLString(cookie);
    }

}
